package com.sixth.system.service.impl;/**
 * @author 633yh
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixth.core.entity.CheckItem;
import com.sixth.core.vo.R;
import com.sixth.system.mapper.checkItemMapper;
import com.sixth.system.service.checkItemService;
import com.sixth.system.vo.CheckItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author     ：Stu YH
 * @date       ：Created in 2024/8/20 19:15
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class checkItemServiceImpl implements checkItemService {
    @Autowired
    private checkItemMapper checkItemMapper;
    @Override
    public R<IPage<CheckItem>> selectByPage(CheckItemVo checkItemVo) {
        Page<CheckItem> page = new Page<>(checkItemVo.getPageNum(), checkItemVo.getPageSize());
        QueryWrapper<CheckItem> wrapper = new QueryWrapper<>();
        if (checkItemVo.getCheckItemName()!=null){
            wrapper.like("check_item_name",checkItemVo.getCheckItemName());
        }
        if (checkItemVo.getStatus()!=null){
            wrapper.eq("status",checkItemVo.getStatus());
        }
        if (checkItemVo.getTypeId()!=null){
            wrapper.eq("type_id",checkItemVo.getTypeId());
        }
        if (checkItemVo.getKeywords()!=null){
            wrapper.like("keywords",checkItemVo.getKeywords());
        }
        Page<CheckItem> checkItemPage = checkItemMapper.selectPage(page, wrapper);
        return R.ok(checkItemPage);

    }

    @Override
    public R addUpdate(CheckItem checkItem) {
        checkItem.setCreateTime(new java.util.Date());
        checkItemMapper.insertOrUpdate(checkItem);
        return R.ok();
    }

    @Override
    public R delete(Long[] checkItemIds) {
        checkItemMapper.deleteBatchIds(Arrays.asList(checkItemIds));
        return R.ok();
    }
}